package com.ctshk.rpc.order.goods.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ctshk.rpc.order.goods.entity.OrderConsigneeInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 订单收货人信息 Mapper 接口
 * </p>
 *
 * @author 姜斌文
 * @since 2021-04-19
 */
public interface OrderConsigneeInfoMapper extends BaseMapper<OrderConsigneeInfo> {

    @Select("SELECT " +
            "t.id,t.order_id,t.consignee,t.consignee_phone,t.consignee_mobile_area_code_id,t.consignee_email,t.consignee_area_id,t.consignee_area_name,t.consignee_address,t.consignee_time,t.gmt_create,t.create_id,t.gmt_modified,t.modified_id,t.is_deleted " +
            "FROM `ctshk-goods-order`.t_order_consignee_info t " +
            "WHERE t.is_deleted = 0 AND t.order_id = #{orderId}")
    OrderConsigneeInfo findConsigneeInfoByOrder(@Param("orderId") Long orderId);


    //INSERT INTO `ctshk-goods-order`.`t_order_consignee_info`
    // (`id`, `order_id`, `consignee`, `consignee_phone`, `consignee_email`, `consignee_area_id`, `consignee_area_name`,
    // `consignee_address`, `consignee_time`, `gmt_create`, `create_id`, `gmt_modified`, `modified_id`, `is_deleted`,
    // `consignee_mobile_area_code_id`) VALUES

    @Insert({
            "<script>" +
                    "INSERT INTO `ctshk-goods-order`.`t_order_consignee_info` " +
                    "<trim prefix=\"(\" suffix=\")\" suffixOverrides=\",\">"+
                    "<if test='id != null'>`id`, </if>" +
                    "<if test='orderId != null'>`order_id`,</if>" +
                    "<if test='consignee != null'>`consignee`,</if>" +
                    "<if test='consigneePhone != null'>`consignee_phone`,</if>" +
                    "<if test='consigneeEmail != null'>`consignee_email`,</if>" +
                    "<if test='consigneeAreaId != null'>`consignee_area_id`,</if>" +
                    "<if test='consigneeAreaName != null'>`consignee_area_name`,</if>" +
                    "<if test='consigneeAddress != null'>`consignee_address`,</if>" +
                    "<if test='consigneeTime != null'>`consignee_time`,</if>" +
                    "<if test='gmtCreate != null'>`gmt_create`,</if>" +
                    "<if test='createId != null'>`create_id`,</if>" +
                    "<if test='gmtModified != null'>`gmt_modified`,</if>" +
                    "<if test='modifiedId != null'>`modified_id`,</if>" +
                    "<if test='consigneeMobileAreaCodeId != null'>`consignee_mobile_area_code_id`,</if>" +
                    "<if test='isDeleted != null'>`is_deleted`,</if>" +
                    "</trim>" +
                    "VALUES "+
                    "<trim prefix=\"(\" suffix=\")\" suffixOverrides=\",\">" +
                    "<if test='id != null'>#{id}, </if>" +
                    "<if test='orderId != null'>#{orderId},</if>" +
                    "<if test='consignee != null'>#{consignee},</if>" +
                    "<if test='consigneePhone != null'>#{consigneePhone},</if>" +
                    "<if test='consigneeEmail != null'>#{consigneeEmail},</if>" +
                    "<if test='consigneeAreaId != null'>#{consigneeAreaId},</if>" +
                    "<if test='consigneeAreaName != null'>#{consigneeAreaName},</if>" +
                    "<if test='consigneeAddress != null'>#{consigneeAddress},</if>" +
                    "<if test='consigneeTime != null'>#{consigneeTime},</if>" +
                    "<if test='gmtCreate != null'>#{gmtCreate},</if>" +
                    "<if test='createId != null'>#{createId},</if>" +
                    "<if test='gmtModified != null'>#{gmtModified},</if>" +
                    "<if test='modifiedId != null'>#{modifiedId},</if>" +
                    "<if test='consigneeMobileAreaCodeId != null'>#{consigneeMobileAreaCodeId},</if>" +
                    "<if test='isDeleted != null'>#{isDeleted},</if>" +
                    "</trim>"+
                    "</script>"
    })
    void insertConsigneeInfo(OrderConsigneeInfo orderConsigneeInfo);
}
